
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>网络访问 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="storage.html" />
    
    
    <link rel="prev" href="interface.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    入门
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../introduction/environment.html">
            
                <a href="../introduction/environment.html">
            
                    
                    环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../introduction/hello.html">
            
                <a href="../introduction/hello.html">
            
                    
                    HelloWorld
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../introduction/dev-and-debug.html">
            
                <a href="../introduction/dev-and-debug.html">
            
                    
                    开发与调试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    参考
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../framework/file.html">
            
                <a href="../framework/file.html">
            
                    
                    文件组织
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../framework/manifest.html">
            
                <a href="../framework/manifest.html">
            
                    
                    manifest文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../framework/nml.html">
            
                <a href="../framework/nml.html">
            
                    
                    nml文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../framework/page.html">
            
                <a href="../framework/page.html">
            
                    
                    页面与组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    组件
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../component/general.html">
            
                <a href="../component/general.html">
            
                    
                    通用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../component/container.html">
            
                <a href="../component/container.html">
            
                    
                    容器组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../component/basics.html">
            
                <a href="../component/basics.html">
            
                    
                    基础组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../component/form.html">
            
                <a href="../component/form.html">
            
                    
                    表单组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../component/media.html">
            
                <a href="../component/media.html">
            
                    
                    媒体组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    接口
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="general.html">
            
                <a href="general.html">
            
                    
                    通用规则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="basic.html">
            
                <a href="basic.html">
            
                    
                    基本功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="interface.html">
            
                <a href="interface.html">
            
                    
                    界面交互
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.4" data-path="request.html">
            
                <a href="request.html">
            
                    
                    网络访问
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="storage.html">
            
                <a href="storage.html">
            
                    
                    文件数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="system.html">
            
                <a href="system.html">
            
                    
                    系统能力
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="media.html">
            
                <a href="media.html">
            
                    
                    图形图像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="share.html">
            
                <a href="share.html">
            
                    
                    分享
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="pay.html">
            
                <a href="pay.html">
            
                    
                    支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="stat.html">
            
                <a href="stat.html">
            
                    
                    统计
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >网络访问</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="&#x6570;&#x636E;&#x8BF7;&#x6C42;">&#x6570;&#x636E;&#x8BF7;&#x6C42;</h3>
<h4 id="&#x63A5;&#x53E3;&#x58F0;&#x660E;">&#x63A5;&#x53E3;&#x58F0;&#x660E;</h4>
<p>{&quot;name&quot;: &quot;system.fetch&quot;}</p>
<h4 id="unifetchfetchobject">uni.fetch.fetch(OBJECT)</h4>
<p>&#x83B7;&#x53D6;&#x7F51;&#x7EDC;&#x6570;&#x636E;&#x3002;</p>
<p>&#x53C2;&#x6570;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x5FC5;&#x586B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">url</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x662F;</td>
<td style="text-align:left">&#x8D44;&#x6E90;url</td>
</tr>
<tr>
<td style="text-align:left">data</td>
<td style="text-align:left">String/Object</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x8BF7;&#x6C42;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x6216;&#x8005;&#x662F; json &#x5BF9;&#x8C61;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">header</td>
<td style="text-align:left">Object</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x8BF7;&#x6C42;&#x7684; header&#xFF0C;&#x4F1A;&#x5C06;&#x5176;&#x6240;&#x6709;&#x5C5E;&#x6027;&#x8BBE;&#x7F6E;&#x5230;&#x8BF7;&#x6C42;&#x7684; header &#x90E8;&#x5206;&#x3002;useragent &#x8BBE;&#x7F6E;&#x65E0;&#x6548;&#x3002;&#x793A;&#x4F8B;&#xFF1A;<code>{&quot;Accept-Encoding&quot;: &quot;gzip, deflate&quot;,&quot;Accept-Language&quot;: &quot;zh-CN,en-US;q=0.8,en;q=0.6&quot;}</code></td>
</tr>
<tr>
<td style="text-align:left">method</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x9ED8;&#x8BA4;&#x4E3A; GET&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#xFF1A;OPTIONS&#xFF0C;GET&#xFF0C;HEAD&#xFF0C;POST&#xFF0C;PUT&#xFF0C;DELETE&#xFF0C;TRACE&#xFF0C;CONNECT</td>
</tr>
<tr>
<td style="text-align:left">success</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x6210;&#x529F;&#x8FD4;&#x56DE;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">fail</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x5931;&#x8D25;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x56E0;&#x4E3A;&#x6743;&#x9650;&#x5931;&#x8D25;</td>
</tr>
<tr>
<td style="text-align:left">complete</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x7ED3;&#x675F;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF08;&#x8C03;&#x7528;&#x6210;&#x529F;&#x3001;&#x5931;&#x8D25;&#x90FD;&#x4F1A;&#x6267;&#x884C;&#xFF09;</td>
</tr>
</tbody>
</table>
<p>data &#x8BF4;&#x660E;</p>
<ul>
<li>&#x5982;&#x679C;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5176;&#x503C;&#x4F5C;&#x4E3A;&#x8BF7;&#x6C42;&#x7684; body&#xFF0C;&#x8BF7;&#x6C42;&#x7684; Content-Type &#x4F1A;&#x88AB;&#x8BBE;&#x7F6E;&#x4E3A; text/plain&#x3002;</li>
<li>&#x5982;&#x679C;&#x662F; json &#x5BF9;&#x8C61;&#xFF0C;&#x4F1A;&#x5C06;&#x5176;&#x6240;&#x6709;&#x5C5E;&#x6027;&#x4F7F;&#x7528; urlencode &#x7F16;&#x7801;&#xFF0C;&#x7EC4;&#x6210;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x4F5C;&#x4E3A;&#x8BF7;&#x6C42;&#x7684; body&#xFF0C;&#x8BF7;&#x6C42;&#x7684; Content-Type &#x4F1A;&#x88AB;&#x8BBE;&#x7F6E;&#x4E3A; application/x-www-form-urlencoded&#x3002;</li>
</ul>
<p>success &#x8FD4;&#x56DE;&#x503C;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">code</td>
<td style="text-align:left">Number</td>
<td style="text-align:left">&#x670D;&#x52A1;&#x5668;&#x72B6;&#x6001; code</td>
</tr>
<tr>
<td style="text-align:left">data</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x5982;&#x679C;&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;&#x7684; header &#x4E2D; type &#x662F; text/* &#x6216; application/json&#x3001;application/javascript&#x3001;application/xml&#xFF0C;&#x503C;&#x662F;&#x6587;&#x672C;&#x5185;&#x5BB9;&#xFF0C;&#x5426;&#x5219;&#x662F;&#x5B58;&#x50A8;&#x7684;&#x4E34;&#x65F6;&#x6587;&#x4EF6;&#x7684; uri&#x3002;&#x4E34;&#x65F6;&#x6587;&#x4EF6;&#x5982;&#x679C;&#x662F;&#x56FE;&#x7247;&#x6216;&#x8005;&#x89C6;&#x9891;&#x5185;&#x5BB9;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x56FE;&#x7247;&#x8BBE;&#x7F6E;&#x5230; image &#x6216; video &#x63A7;&#x4EF6;&#x4E0A;&#x663E;&#x793A;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">headers</td>
<td style="text-align:left">Object</td>
<td style="text-align:left">&#x670D;&#x52A1;&#x5668; response &#x7684;&#x6240;&#x6709; header</td>
</tr>
</tbody>
</table>
<p>&#x793A;&#x4F8B;</p>
<pre><code class="lang-javascript">uni.fetch.fetch({
  url: <span class="hljs-string">&quot;http://www.example.com&quot;</span>,
  success: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;title: &quot;</span> + <span class="hljs-built_in">JSON</span>.parse(data.data).title);
  },
  fail: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data, code</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;handling fail, code=&quot;</span> + code);
  }
});
</code></pre>
<h4 id="&#x5B89;&#x5168;&#x8981;&#x6C42;">&#x5B89;&#x5168;&#x8981;&#x6C42;</h4>
<p>&#x5BF9;&#x4E8E;HTTPS&#x8BF7;&#x6C42;&#xFF0C;&#x5BF9;&#x8BC1;&#x4E66;&#x8981;&#x6C42;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>HTTPS&#x8BC1;&#x4E66;&#x5FC5;&#x987B;&#x6709;&#x6548;&#x3002;&#x8BC1;&#x4E66;&#x5FC5;&#x987B;&#x88AB;&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;&#xFF0C;&#x4E0D;&#x652F;&#x6301;&#x81EA;&#x7B7E;&#x540D;&#x8BC1;&#x4E66;&#xFF0C;&#x90E8;&#x7F72;SSL&#x8BC1;&#x4E66;&#x7684;&#x7F51;&#x7AD9;&#x57DF;&#x540D;&#x5FC5;&#x987B;&#x4E0E;&#x8BC1;&#x4E66;&#x9881;&#x53D1;&#x7684;&#x57DF;&#x540D;&#x4E00;&#x81F4;&#xFF0C;&#x8BC1;&#x4E66;&#x5FC5;&#x987B;&#x5728;&#x6709;&#x6548;&#x671F;&#x5185;&#x3002;</li>
<li>TLS&#x5FC5;&#x987B;&#x652F;&#x6301;1.1&#x53CA;&#x4EE5;&#x4E0A;&#x7248;&#x672C;&#x3002;&#x90E8;&#x5206;&#x65E7;Android&#x673A;&#x578B;&#xFF08;4.4&#x4EE5;&#x4E0B;&#xFF09;&#x8FD8;&#x672A;&#x652F;&#x6301; TLS1.1&#xFF0C;&#x8BF7;&#x786E;&#x4FDD;HTTPS&#x670D;&#x52A1;&#x5668;&#x7684;TLS&#x7248;&#x672C;&#x80FD;&#x591F;&#x540C;&#x65F6;&#x652F;&#x6301; TLS1.1 &#x53CA;&#x4EE5;&#x4E0B;&#x7248;&#x672C;&#xFF0C;&#x4ECE;&#x5B89;&#x5168;&#x6027;&#x8003;&#x8651;&#xFF0C;&#x5EFA;&#x8BAE;&#x4E5F;&#x652F;&#x6301;TLS1.2&#xFF0C;&#x5728;&#x914D;&#x7F6E;&#x52A0;&#x5BC6;&#x5957;&#x4EF6;&#x65F6;&#x6392;&#x9664;&#x4E0D;&#x5B89;&#x5168;&#x7B97;&#x6CD5;&#xFF1A;DES/3DES&#xFF08;&#x9664;&#x5BC6;&#x94A5;K1&#x2260;K2&#x2260;K3&#x5916;&#x7684;&#x573A;&#x666F;&#xFF09;/SKIPJACK/RC2/MD2/MD4/SHA1&#x3002;</li>
</ul>
<p>&#x90E8;&#x5206;CA&#x53EF;&#x80FD;&#x4E0D;&#x88AB;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;&#xFF0C;&#x8BF7;&#x5F00;&#x53D1;&#x8005;&#x5728;&#x9009;&#x62E9;&#x8BC1;&#x4E66;&#x65F6;&#x6CE8;&#x610F;Android&#x7CFB;&#x7EDF;&#x7684;&#x76F8;&#x5173;&#x901A;&#x544A;&#x3002;</p>
<h3 id="&#x4E0A;&#x4F20;&#x4E0B;&#x8F7D;">&#x4E0A;&#x4F20;&#x4E0B;&#x8F7D;</h3>
<h4 id="&#x63A5;&#x53E3;&#x58F0;&#x660E;">&#x63A5;&#x53E3;&#x58F0;&#x660E;</h4>
<p>{&quot;name&quot;: &quot;system.request&quot;}</p>
<h4 id="unirequestuploadobject">uni.request.upload(OBJECT)</h4>
<p>&#x4E0A;&#x4F20;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x53C2;&#x6570;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x5FC5;&#x586B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">url</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x662F;</td>
<td style="text-align:left">&#x8D44;&#x6E90;url</td>
</tr>
<tr>
<td style="text-align:left">header</td>
<td style="text-align:left">Object</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x8BF7;&#x6C42;&#x7684; header&#xFF0C;&#x4F1A;&#x5C06;&#x5176;&#x6240;&#x6709;&#x5C5E;&#x6027;&#x8BBE;&#x7F6E;&#x5230;&#x8BF7;&#x6C42;&#x7684; header &#x90E8;&#x5206;&#x3002;useragent &#x8BBE;&#x7F6E;&#x65E0;&#x6548;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">method</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x9ED8;&#x8BA4;&#x4E3A; GET&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#xFF1A;POST&#xFF0C;PUT</td>
</tr>
<tr>
<td style="text-align:left">files</td>
<td style="text-align:left">Array</td>
<td style="text-align:left">&#x662F;</td>
<td style="text-align:left">&#x9700;&#x8981;&#x4E0A;&#x4F20;&#x7684;&#x6587;&#x4EF6;&#x5217;&#x8868;&#xFF0C;&#x4F7F;&#x7528; multipart/form-data &#x65B9;&#x5F0F;&#x63D0;&#x4EA4;&#x3002;files &#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A; file &#x5BF9;&#x8C61;&#x7684;&#x6570;&#x7EC4;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">success</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x6210;&#x529F;&#x8FD4;&#x56DE;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">fail</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x5931;&#x8D25;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x56E0;&#x4E3A;&#x6743;&#x9650;&#x5931;&#x8D25;</td>
</tr>
<tr>
<td style="text-align:left">complete</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x7ED3;&#x675F;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF08;&#x8C03;&#x7528;&#x6210;&#x529F;&#x3001;&#x5931;&#x8D25;&#x90FD;&#x4F1A;&#x6267;&#x884C;&#xFF09;</td>
</tr>
</tbody>
</table>
<p>files &#x53C2;&#x6570;&#x8BF4;&#x660E;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x5FC5;&#x586B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">filename</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">multipart&#x63D0;&#x4EA4;&#x65F6;&#xFF0C;header&#x4E2D;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">name</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">multipart&#x63D0;&#x4EA4;&#x65F6;&#xFF0C;&#x8868;&#x5355;&#x7684;&#x9879;&#x76EE;&#x540D;&#xFF0C;&#x9ED8;&#x8BA4;file&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">uri</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x662F;</td>
<td style="text-align:left">&#x6587;&#x4EF6;&#x7684;&#x672C;&#x5730;&#x5730;&#x5740;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">type</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x6587;&#x4EF6;&#x7684;Content-Type&#x683C;&#x5F0F;&#xFF0C;&#x4E0D;&#x586B;&#x5219;&#x4F1A;&#x6839;&#x636E;filename&#x6216;uri&#x7684;&#x540E;&#x7F00;&#x4ECE;&#x7CFB;&#x7EDF;&#x7684;&#x6620;&#x5C04;&#x8868;&#x4E2D;&#x67E5;&#x8BE2;&#x5BF9;&#x5E94;&#x7684;Content-Type&#xFF0C;&#x5047;&#x5982;&#x83B7;&#x53D6;&#x5931;&#x8D25;&#x5219;&#x62A5;&#x53C2;&#x6570;&#x975E;&#x6CD5;&#x5F02;&#x5E38;</td>
</tr>
</tbody>
</table>
<p>success &#x8FD4;&#x56DE;&#x503C;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">code</td>
<td style="text-align:left">Number</td>
<td style="text-align:left">&#x670D;&#x52A1;&#x5668;&#x72B6;&#x6001;code</td>
</tr>
<tr>
<td style="text-align:left">data</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x5982;&#x679C;&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;&#x7684;header&#x4E2D;type&#x662F;text/*&#x6216;application/json&#x3001;application/javascript&#x3001;application/xml&#xFF0C;&#x503C;&#x662F;&#x6587;&#x672C;&#x5185;&#x5BB9;&#xFF0C;&#x5426;&#x5219;&#x662F;&#x5B58;&#x50A8;&#x7684;&#x4E34;&#x65F6;&#x6587;&#x4EF6;&#x7684;uri&#x4E34;&#x65F6;&#x6587;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x56FE;&#x7247;&#x6216;&#x8005;&#x89C6;&#x9891;&#x5185;&#x5BB9;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x56FE;&#x7247;&#x8BBE;&#x7F6E;&#x5230;image&#x6216;video&#x63A7;&#x4EF6;&#x4E0A;&#x663E;&#x793A;</td>
</tr>
<tr>
<td style="text-align:left">headers</td>
<td style="text-align:left">Object</td>
<td style="text-align:left">&#x670D;&#x52A1;&#x5668;response&#x7684;&#x6240;&#x6709;header</td>
</tr>
</tbody>
</table>
<p>&#x793A;&#x4F8B;</p>
<pre><code class="lang-javascript">uni.request.upload({
  url: <span class="hljs-string">&quot;http://www.example.com&quot;</span>,
  files: [{
    uri: <span class="hljs-string">&quot;internal://xxx/xxx/test&quot;</span>,
    name: <span class="hljs-string">&quot;file1&quot;</span>,
    filename: <span class="hljs-string">&quot;test.png&quot;</span>
  }],
  success: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;handling success&quot;</span>);
  },
  fail: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data, code</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;handling fail, code=&quot;</span> + code);
  }
});
</code></pre>
<h4 id="unirequestdownloadobject">uni.request.download(OBJECT)</h4>
<p>&#x4E0B;&#x8F7D;&#x6587;&#x4EF6;</p>
<p>&#x53C2;&#x6570;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x5FC5;&#x586B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">url</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x662F;</td>
<td style="text-align:left">&#x8D44;&#x6E90;url</td>
</tr>
<tr>
<td style="text-align:left">header</td>
<td style="text-align:left">Object</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x8BF7;&#x6C42;&#x7684;header&#xFF0C;&#x4F1A;&#x5C06;&#x5176;&#x6240;&#x6709;&#x5C5E;&#x6027;&#x8BBE;&#x7F6E;&#x5230;&#x8BF7;&#x6C42;&#x7684;header&#x90E8;&#x5206;&#x3002;useragent&#x8BBE;&#x7F6E;&#x65E0;&#x6548;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">success</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x6210;&#x529F;&#x8FD4;&#x56DE;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">fail</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x5931;&#x8D25;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">complete</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x7ED3;&#x675F;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF08;&#x8C03;&#x7528;&#x6210;&#x529F;&#x3001;&#x5931;&#x8D25;&#x90FD;&#x4F1A;&#x6267;&#x884C;&#xFF09;</td>
</tr>
</tbody>
</table>
<p>success&#x8FD4;&#x56DE;&#x503C;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">token</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x4E0B;&#x8F7D;&#x7684;token&#xFF0C;&#x6839;&#x636E;&#x6B64;token&#x83B7;&#x53D6;&#x4E0B;&#x8F7D;&#x72B6;&#x6001;</td>
</tr>
</tbody>
</table>
<p>&#x793A;&#x4F8B;</p>
<pre><code class="lang-javascript">uni.request.download({
  url: <span class="hljs-string">&quot;http://www.example.com&quot;</span>,
  success: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;handling success&quot;</span> + data.token);
  },
  fail: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data, code</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;handling fail, code=&quot;</span> + code);
  }
});
</code></pre>
<h4 id="unirequestondownloadcompleteobject">uni.request.onDownloadComplete(OBJECT)</h4>
<p>&#x76D1;&#x542C;&#x4E0B;&#x8F7D;&#x4EFB;&#x52A1;&#x3002;</p>
<p>&#x53C2;&#x6570;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x5FC5;&#x586B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">token</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x662F;</td>
<td style="text-align:left">download&#x63A5;&#x53E3;&#x8FD4;&#x56DE;&#x7684;token</td>
</tr>
<tr>
<td style="text-align:left">success</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x6210;&#x529F;&#x8FD4;&#x56DE;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">fail</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x5931;&#x8D25;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">complete</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x5426;</td>
<td style="text-align:left">&#x7ED3;&#x675F;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF08;&#x8C03;&#x7528;&#x6210;&#x529F;&#x3001;&#x5931;&#x8D25;&#x90FD;&#x4F1A;&#x6267;&#x884C;&#xFF09;</td>
</tr>
</tbody>
</table>
<p>success &#x8FD4;&#x56DE;&#x503C;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">uri</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x4E0B;&#x8F7D;&#x6587;&#x4EF6;&#x7684;uri&#xFF0C;&#x4F1A;&#x5B58;&#x50A8;&#x5728;&#x6587;&#x4EF6;&#x7EC4;&#x7EC7;&#x7684;mass&#x5206;&#x533A;&#x4E0B;</td>
</tr>
</tbody>
</table>
<p>fail&#x8FD4;&#x56DE;&#x9519;&#x8BEF;&#x7801;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x9519;&#x8BEF;&#x7801;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">1000</td>
<td style="text-align:left">&#x4E0B;&#x8F7D;&#x5931;&#x8D25;</td>
</tr>
<tr>
<td style="text-align:left">1001</td>
<td style="text-align:left">&#x4E0B;&#x8F7D;&#x4EFB;&#x52A1;&#x4E0D;&#x5B58;&#x5728;</td>
</tr>
</tbody>
</table>
<p>&#x793A;&#x4F8B;</p>
<pre><code class="lang-javascript">uni.request.onDownloadComplete({
  token: <span class="hljs-string">&quot;123&quot;</span>,
  success: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;handling success&quot;</span> + data.uri);
  },
  fail: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data, code</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;handling fail, code=&quot;</span> + code);
  }
});
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="interface.html" class="navigation navigation-prev " aria-label="Previous page: 界面交互">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="storage.html" class="navigation navigation-next " aria-label="Next page: 文件数据">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"网络访问","level":"1.5.4","depth":2,"next":{"title":"文件数据","level":"1.5.5","depth":2,"path":"api/storage.md","ref":"api/storage.md","articles":[]},"previous":{"title":"界面交互","level":"1.5.3","depth":2,"path":"api/interface.md","ref":"api/interface.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"api/request.md","mtime":"2018-02-21T02:33:35.084Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-04-04T08:24:24.953Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

